package tt.dz.biz.dao.user;

import java.util.List;
import org.springframework.stereotype.Repository;
import tt.dz.biz.dao.BaseDAO;
import tt.dz.common.DZStringUtil;
import tt.dz.vo.OfflineIdentityCardHisVO;

@Repository("offlineIdentityCardHisDAO")
public class OfflineIdentityCardHisDAO
  extends BaseDAO
{
  private static final String INSERT_OFFLINE_IDENTITY_CAR_HIS = "insert into ms_offline_identity_card_his(card_no,state,created_by,created_time) values (:cardNo, :state, :createdBy, :createdTime)";
  private static final String QUERY_OFFLINE_IDENTITY_CAR_HIS_BY_CONDITION = "select t1.card_no, t1.state, t1.created_by, t1.created_time,t2.name as createdName from ms_offline_identity_card_his t1  left join pub_oper_list t2 on t2.manager_id = t1.created_by  where 1 = 1 ";
  
  public int[] batchInsertOfflineIdentityCardHis(List<OfflineIdentityCardHisVO> offlineIdentityCardHises)
  {
    return super.batchSave("insert into ms_offline_identity_card_his(card_no,state,created_by,created_time) values (:cardNo, :state, :createdBy, :createdTime)", offlineIdentityCardHises);
  }
  
  public int insertOfflineIdentityCardHis(OfflineIdentityCardHisVO offlineIdentityCardHis)
  {
    return super.save("insert into ms_offline_identity_card_his(card_no,state,created_by,created_time) values (:cardNo, :state, :createdBy, :createdTime)", offlineIdentityCardHis);
  }
  
  public List<OfflineIdentityCardHisVO> queryOfflineIdentityCardHisByCondition(OfflineIdentityCardHisVO offlineIdentityCardHis)
  {
    StringBuffer sb = new StringBuffer("select t1.card_no, t1.state, t1.created_by, t1.created_time,t2.name as createdName from ms_offline_identity_card_his t1  left join pub_oper_list t2 on t2.manager_id = t1.created_by  where 1 = 1 ");
    if (offlineIdentityCardHis != null)
    {
      if (!DZStringUtil.isEmpty(offlineIdentityCardHis.getCardNo())) {
        sb.append(" and t1.card_no = :cardNo ");
      }
      if (offlineIdentityCardHis.getStartDate() != null) {
        sb.append(" and t1.created_time >= :startDate ");
      }
      if (offlineIdentityCardHis.getEndDate() != null) {
        sb.append(" and t1.created_time <= :endDate ");
      }
    }
    return super.queryForList(sb.toString(), offlineIdentityCardHis == null ? new OfflineIdentityCardHisVO() : offlineIdentityCardHis, OfflineIdentityCardHisVO.class);
  }
}
